package design.factory.abstractFactory;

public class HandGun extends AbstractGun implements Gun {
    public static final int CHARGER_CAPACITY = 7; // 弹夹容量
    @Override
    public void shoot() {
        while(true) {
            int c = charger.size();
            if (c < 1) {
                System.out.println("咔..............没子弹了");
                break;
            }
            super.shoot();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    @Override
    public void loading(Bullet bullet) {
        if(bullet.getClass() != HandGunBullet.class) {
            throw new RuntimeException("子弹规格不符");
        }
        if(charger.size() < CHARGER_CAPACITY) {
            super.loading(bullet);
        }
    }
}
